import time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class PostsEdit:
    url=""
    driver=""

    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    # 帖子编辑页
    def PostsEdit(self):
        #找到首页-点击“发布帖子”按钮-到帖子编辑页
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #是否有模块选择
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")

        #测试异常发布：不输入标题，点击发布，是否出现提示输入帖子标题
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").clear()
        time.sleep(5)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        print(self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div").text)

        #测试异常发布：输入标题，不输入内容，点击发布，是否出现提示输入帖子内容
        title_label=self.driver.find_element(By.CSS_SELECTOR,"#article_post_title")
        title_label.send_keys("这是帖子标题")
        # # tab键跳转到输入内容的位置
        # title_label.send_keys(Keys.TAB)
        # ele = self.driver.switch_to.active_element
        # #不输入内容
        # ele.clear()
        time.sleep(3)
        #点击发布
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        print(self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div").text)

        #测试正常发布：输入标题和内容，点击发布，是否出现提示发帖成功
        title_label.clear()
        title_label.send_keys("帖子标题")
        title_label.send_keys(Keys.TAB)
        ele = self.driver.switch_to.active_element
        ele.send_keys("你好")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        print(self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text)

        ForumDriver.getScreenShot()


